package generated.com.euncet.example.dictionaries;

import generated.rmo.utils.EntityManagerFactorySingleton;


public class ProductDictionary {
	@SuppressWarnings("unchecked")
	public static java.util.List<com.euncet.example.Product> getProducts()
	{
		javax.persistence.EntityManager em = generated.rmo.utils.EntityManagerFactorySingleton.getEntityManager();
		
		String q = "SELECT p FROM Product p";
		
		javax.persistence.Query query = em.createQuery(q);
		
		java.util.List<com.euncet.example.Product> results = query.getResultList();
		
		return results;
	}
	
	public static com.euncet.example.Product getProductById(long id)
	{
		javax.persistence.EntityManager em = generated.rmo.utils.EntityManagerFactorySingleton.getEntityManager();
		
		com.euncet.example.Product result = em.find(com.euncet.example.Product.class, id);
		
		return result;
	}
	
	public static void addProduct(com.euncet.example.Product product)
	{
		javax.persistence.EntityManager em = generated.rmo.utils.EntityManagerFactorySingleton.getEntityManager();
		
	    em.persist(product);
	}
	
	public static void removeProduct(long id)
	{
		removeProduct(getProductById(id));
	}
	
	public static void removeProduct(com.euncet.example.Product product)
	{
		javax.persistence.EntityManager em = generated.rmo.utils.EntityManagerFactorySingleton.getEntityManager();
		
	    em.remove(product);
	}
	
	@SuppressWarnings("unchecked")
	public static java.util.List<com.euncet.example.Product> getCategoryProducts(com.euncet.example.Category category)
	{
		javax.persistence.EntityManager em = EntityManagerFactorySingleton.getEntityManager();
		
		String q = "SELECT c FROM Product c "
					+ "WHERE c.categoryId = " + category.getId();
		
		javax.persistence.Query query = em.createQuery(q);
		
		java.util.List<com.euncet.example.Product> results = query.getResultList();
		
		return results;
	}
}
